package com.lyshop.jinding.adapters;

import android.content.Context;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.lyshop.jinding.R;
import com.lyshop.jinding.base.BaseRVAdapter;
import com.lyshop.jinding.base.BaseRVHolder;
import com.lyshop.jinding.bean.IntegralRecordBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class IntegralRecordAdapter extends BaseRVAdapter {
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);

    public IntegralRecordAdapter(Context context, List list) {
        super(context, list);
    }

    @Override
    public int onCreateViewLayoutID(int viewType) {
        return R.layout.item_integral_record;
    }

    @Override
    public void onBindView(BaseRVHolder holder, int position) {
        TextView title = holder.getViewHolder().get(R.id.title_tv);
        TextView tv_time = holder.getViewHolder().get(R.id.time_tv);
        TextView integral = holder.getViewHolder().get(R.id.integral_tv);
        IntegralRecordBean bean = (IntegralRecordBean) mList.get(position);
        title.setText(bean.getRemark());
        tv_time.setText(dateFormat.format(new Date((long) (bean.getAdd_time() * 1000.0f))));

        Integer integer = Integer.valueOf(bean.getIntegral_num());
        if(integer>0){
            integral.setTextColor(ContextCompat.getColor(mContext, R.color.buy_red));
            integral.setText("+"+bean.getIntegral_num());
        }else {
            integral.setTextColor(ContextCompat.getColor(mContext, R.color.buy_green));
            integral.setText(bean.getIntegral_num());
        }
    }
}
